package bb.lanxing.mvp.view.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import bb.lanxing.R;
import bb.lanxing.model.json.level.RuleDetail;
import bb.lanxing.util.Log;
import bb.lanxing.util.image.GlideUtils;
import java.util.ArrayList;
import java.util.List;

public class RuleDetailAdapter extends BaseAdapter {
    final static private String TAG = "RuleDetailAdapter";
    private boolean isSelect;
    private Context mContext;
    private List<RuleDetail> ruleDetailList;

    @Override
    public long getItemId(int i) {
        return i;
    }

    public RuleDetailAdapter(Context context, boolean z, List<RuleDetail> list) {
        new ArrayList();
        this.mContext = context;
        this.isSelect = z;
        this.ruleDetailList = list;
    }

    public void updateData(List<RuleDetail> list) {
        Log.v(TAG, "[RuleDetailAdapter] updateData, list = " + list);
        this.ruleDetailList.clear();
        this.ruleDetailList.addAll(list);
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return this.ruleDetailList.size();
    }

    @Override
    public Object getItem(int i) {
        return this.ruleDetailList.get(i);
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder viewHolder;
        Log.v(TAG, "[RuleDetailAdapter] getView, position = " + i + ", convertView = " + view);
        if (view == null) {
            view = View.inflate(this.mContext, R.layout.item_rule_detail_gridview, null);
            viewHolder = new ViewHolder(view);
            view.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) view.getTag();
        }
        RuleDetail ruleDetail = (RuleDetail) getItem(i);
        viewHolder.itemText.setText(ruleDetail.getRuleDesc());
        GlideUtils.companion.loadCircleImage(viewHolder.itemIcon.getContext(),
                GlideUtils.companion.appendImagePath(this.isSelect ? ruleDetail.getRulePicOn() : ruleDetail.getRulePicOff(), 11),
                viewHolder.itemIcon, R.drawable.ic_default, R.drawable.ic_default);
        return view;
    }

    class ViewHolder {
        private ImageView itemIcon;
        private TextView itemText;

        private void bindView(View view) {
            this.itemIcon = (ImageView) view.findViewById(R.id.itemIcon);
            this.itemText = (TextView) view.findViewById(R.id.itemText);
        }

        ViewHolder(View view) {
            bindView(view);
        }
    }
}
